<html>
<head><meta charset="utf-8"><title>Needless Borrow Pedantry · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Needless.20Borrow.20Pedantry.html">Needless Borrow Pedantry</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227810710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Needless%20Borrow%20Pedantry/near/227810710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Needless.20Borrow.20Pedantry.html#227810710">(Feb 25 2021 at 18:07)</a>:</h4>
<p>I was implementing something like <code>needless_borrow</code> and then realized that <code>needless_borrow</code> already exists in the nursery. Ho hum. Anyways, I thought of no less than four different variables that this lint could be configured on. I know this is a picky lint to begin with, but am I over-complicating it? Any feedback?</p>
<ul>
<li><code>needless-borrow-deref: bool</code> default <code>true</code> unless - only lint borrows when every usage is derefed or autoderefed</li>
<li><code>needless-borrow-copy: bool</code> default <code>true</code> - include borrows of any <code>Copy</code> type in addition to references</li>
<li><code>needless-borrow-ref: bool</code> default <code>true</code> - include borrows from a <code>ref</code> binding</li>
<li><code>needless-borrow-binding-mode: bool</code> default <code>false</code> - include borrows caused by the binding mode (<code>match &amp;x</code>)</li>
</ul>
<p>To clarify, the fix for binding mode is to change <code>match x</code> to <code>match *x</code> and add <code>ref</code> on any bindings that still need to borrow. Yeah, not a good default lint, but this fits my style preference for one. <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>
<p>Finally, I'm hoping to make this lint warn-by-default with the deref option on to avoid FPs. Is it possible to change the default config if <code>pedantic</code> is on?</p>



<a name="227900894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Needless%20Borrow%20Pedantry/near/227900894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Needless.20Borrow.20Pedantry.html#227900894">(Feb 26 2021 at 09:12)</a>:</h4>
<p>I don't really know the context about the lint (why it is in nursery and so on).</p>
<blockquote>
<p>Is it possible to change the default config if pedantic is on?</p>
</blockquote>
<p>Maybe you could use <code>utils::run_lints</code> to determine, if the lint is enabled. But I don't think we know if the configuration is set in a config file or is the default configuration.</p>



<a name="228000418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Needless%20Borrow%20Pedantry/near/228000418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Needless.20Borrow.20Pedantry.html#228000418">(Feb 26 2021 at 21:51)</a>:</h4>
<p>I think I need to rephrase: In the absence of any user config, is it possible for clippy to determine the default configuration value based on whether pedantic is enabled? Or, can I have <code>needless_borrow</code> be more noisy by default when <code>warn(pedantic)</code> is on?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>